// pages/giftCard/giftCardProduct.js
var requests = require('../../requests/api.js');
import util from '../../utils/util.js'

let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    goods: [],
    groupImage: "",
    showModalStatus: false,
    screenWidth: wx.getSystemInfoSync().windowWidth - 40,


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    new app.WeToast();
    this.request_giftCardProduct()
  },
  //NET 
  request_giftCardProduct: function() {
    const self = this

    requests.getGiftCardProduct((res) => {
      console.log(res)
      self.setData({
        groupImage: res.data.groupImage,
        goods: res.data.productList
      })
    }, (data) => {
      if (util.alertNetworkError(data)) {
        self.wetoast.toast({
          title: data.resMsg,
        })
      }
    }, () => {});
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },


  toDetailsTap: function(e) {
    var id = e.currentTarget.dataset.productid;
    console.log("---------------" + id)
    wx.navigateTo({
      url: '../product/productDetail?productId=' + id,
    })
  },

  useRuler: function() {
    wx.navigateTo({
      url: '../giftCard/giftCardRuler',
    })

  },
  //使用记录弹窗
  showModal: function() {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 100)
  },
  hideModal: function() {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(200).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 100)
  }
})